<template>
  <div>
    <el-card>
      <el-form>
        <el-form-item label="时间范围">
          <el-date-picker
            size="mini"
            v-model="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
          <el-button @click="getOrderTotal" size="mini" type="primary"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
      <chart-bar :chartBar="chartBar"></chart-bar>
    </el-card>
  </div>
</template>

<script>
import { api_order_ordertotal } from "@/api/order";
import { YMDHms } from "@/filters/index";
import ChartBar from "./chart-bar.vue";
export default {
  components: {
    ChartBar,
  },
  data() {
    return {
      date: [],
      chartBar: {},
    };
  },
  methods: {
    async getOrderTotal() {
      let res = await api_order_ordertotal({
        date: JSON.stringify(this.date),
      });
      let { data } = res.data;
      // 处理数据
      let xData = data.map((v) => YMDHms(v.orderTime));
      let series = [
        {
          type: "bar",
          name: "金额数据",
          data: data.map((v) => v.orderAmount),
        },
      ];
      this.chartBar = { xData, series };
      // //   画图
      // this.renderLine({
      //   xData,
      //   series,
      //   title: "商品统计",
      // });
    },
  },

  mounted() {
    this.getOrderTotal();
  },
};
</script>

<style lang="scss" scoped>
.el-button {
  margin-left: 15px;
}
.echarts {
  height: 400px;
  margin-top: 50px;
}
</style>